//---------------------------------------------------------------------------
//
// Name:        DeadProxyFrm.cpp
// Author:      Carl Chatfield
// Created:     1/5/2008 6:48:54 PM
// Description: DeadProxyFrm class implementation
//
//---------------------------------------------------------------------------

#include "DeadProxyFrm.h"
#include "DeadProxyApp.h"

//Do not add custom headers between
//Header Include Start and Header Include End
//wxDev-C++ designer will remove them
////Header Include Start
////Header Include End

//----------------------------------------------------------------------------
// DeadProxyFrm
//----------------------------------------------------------------------------
//Add Custom Events only in the appropriate block.
//Code added in other places will be removed by wxDev-C++
////Event Table Start
BEGIN_EVENT_TABLE(DeadProxyFrm,wxFrame)
	////Manual Code Start
	EVT_LOG_MESSAGE(wxLOG_MESSAGE_ID, DeadProxyFrm::LogMessage)
	EVT_UPDATE_CLIENT_BOX(wxUPDATE_CLIENT_BOX_ID, DeadProxyFrm::UpdateClientBox)
	EVT_UPDATE_PACKET_BOX(wxUPDATE_PACKET_BOX_ID, DeadProxyFrm::UpdatePacketBox)
	EVT_SET_PACKET_STRING(wxSET_PACKET_STRING_ID, DeadProxyFrm::SetPacketString)
	EVT_INIT_CLIENT_SELECT(wxINIT_CLIENT_SELECT_ID, DeadProxyFrm::InitClientSelect)
	EVT_SET_MESSAGE_INFO(wxSET_MESSAGE_INFO_ID, DeadProxyFrm::SetMessageInfo)
	EVT_UPDATE_MESSAGE_BOX(wxUPDATE_MESSAGE_BOX_ID, DeadProxyFrm::UpdateMessageBox)
	EVT_UPDATE_CHANNEL_BOX(wxUPDATE_CHANNEL_BOX_ID, DeadProxyFrm::UpdateChannelBox)
	////Manual Code End
	
	EVT_CLOSE(DeadProxyFrm::OnClose)
	EVT_COMBOBOX(ID_TOOLBARCLIENTSELECTCOMBOBOX,DeadProxyFrm::ToolBarClientSelectComboBoxSelected)
	EVT_BUTTON(ID_MICLEARALLLOGSBUTTON,DeadProxyFrm::MIClearAllLogsButtonClick)
	EVT_BUTTON(ID_MICLEARCHANNELBUTTON,DeadProxyFrm::MIClearChannelButtonClick)
	EVT_LISTBOX(ID_MESSAGELISTBOX,DeadProxyFrm::MessageListBoxSelected)
	EVT_LISTBOX(ID_CHANNELLISTBOX,DeadProxyFrm::ChannelListBoxSelected)
	EVT_BUTTON(ID_CLEARPACKETSBUTTON,DeadProxyFrm::ClearPacketsButtonClick)
	EVT_BUTTON(ID_CLEARLOGBUTTON,DeadProxyFrm::ClearLogButtonClick)
	EVT_TOGGLEBUTTON(ID_SHOWPACKETSTOGGLEBUTTON,DeadProxyFrm::ShowPacketsToggleButtonClick)
	EVT_BUTTON(ID_TESTBUTTON,DeadProxyFrm::TestButtonClick)
	EVT_BUTTON(ID_LAUNCHCLIENTBUTTON,DeadProxyFrm::LaunchClientButtonClick)
	EVT_LISTBOX(ID_SELECTPACKETLISTBOX,DeadProxyFrm::SelectPacketListBoxSelected)
	EVT_RADIOBOX(ID_LOGPACKETSRADIOBOX,DeadProxyFrm::LogPacketsRadioBoxClick)
	EVT_LISTBOX(ID_CLIENTSELECTLISTBOX,DeadProxyFrm::ClientSelectListBoxSelected)
END_EVENT_TABLE()
////Event Table End

DeadProxyFrm::DeadProxyFrm(wxWindow *parent, wxWindowID id, const wxString &title, const wxPoint &position, const wxSize& size, long style)
: wxFrame(parent, id, title, position, size, style)
{
	CreateGUIControls();
}

DeadProxyFrm::~DeadProxyFrm()
{
}

void DeadProxyFrm::CreateGUIControls()
{
	//Do not add custom code between
	//GUI Items Creation Start and GUI Items Creation End
	//wxDev-C++ designer will remove them.
	//Add the custom code before or after the blocks
	////GUI Items Creation Start

	MainNotebook = new wxNotebook(this, ID_MAINNOTEBOOK, wxPoint(0,21),wxSize(522,335));
	MainNotebook->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	WxProxyPage = new wxPanel(MainNotebook, ID_WXPROXYPAGE, wxPoint(4,24), wxSize(514,307));
	WxProxyPage->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
	MainNotebook->AddPage(WxProxyPage, wxT("Proxy"));

	WxStaticBox1 = new wxStaticBox(WxProxyPage, ID_WXSTATICBOX1, wxT("Client Info"), wxPoint(6,6), wxSize(220,140));
	WxStaticBox1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	wxArrayString arrayStringFor_ClientSelectListBox;
	ClientSelectListBox = new wxListBox(WxProxyPage, ID_CLIENTSELECTLISTBOX, wxPoint(13,23), wxSize(90,100), arrayStringFor_ClientSelectListBox, wxLB_SINGLE);
	ClientSelectListBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	PacketsStaticBox = new wxStaticBox(WxProxyPage, ID_PACKETSSTATICBOX, wxT("Packets"), wxPoint(236,6), wxSize(198,140));
	PacketsStaticBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	/* Recv
	Send
	Both
	*/
	wxArrayString arrayStringFor_LogPacketsRadioBox;
	arrayStringFor_LogPacketsRadioBox.Add(wxT("Off"));
	arrayStringFor_LogPacketsRadioBox.Add(wxT("Send"));
	arrayStringFor_LogPacketsRadioBox.Add(wxT("Recv"));
	arrayStringFor_LogPacketsRadioBox.Add(wxT("Both"));
	LogPacketsRadioBox = new wxRadioBox(WxProxyPage, ID_LOGPACKETSRADIOBOX, wxT("Log Packets"), wxPoint(243,24), wxSize(75,100), arrayStringFor_LogPacketsRadioBox, 1, wxRA_SPECIFY_COLS, wxDefaultValidator, wxT("LogPacketsRadioBox"));
	LogPacketsRadioBox->SetSelection(0);
	LogPacketsRadioBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	wxArrayString arrayStringFor_SelectPacketListBox;
	SelectPacketListBox = new wxListBox(WxProxyPage, ID_SELECTPACKETLISTBOX, wxPoint(321,23), wxSize(108,100), arrayStringFor_SelectPacketListBox, wxLB_SINGLE);
	SelectPacketListBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	SelectFileButton = new wxButton(WxProxyPage, ID_SELECTFILEBUTTON, wxT("Select File"), wxPoint(243,124), wxSize(75,19), 0, wxDefaultValidator, wxT("SelectFileButton"));
	SelectFileButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	LaunchClientButton = new wxButton(WxProxyPage, ID_LAUNCHCLIENTBUTTON, wxT("Launch Client"), wxPoint(13,124), wxSize(90,19), 0, wxDefaultValidator, wxT("LaunchClientButton"));
	LaunchClientButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	FileNameStaticText = new wxStaticText(WxProxyPage, ID_FILENAMESTATICTEXT, wxT("None"), wxPoint(321,126), wxDefaultSize, 0, wxT("FileNameStaticText"));
	FileNameStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	TestButton = new wxButton(WxProxyPage, ID_TESTBUTTON, wxT("TEST"), wxPoint(125,101), wxSize(75,25), 0, wxDefaultValidator, wxT("TestButton"));
	TestButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	OutputEditBox = new wxTextCtrl(WxProxyPage, ID_OUTPUTEDITBOX, wxT("Welcome to DeadProxy"), wxPoint(2,150), wxSize(510,150), wxVSCROLL | wxTE_READONLY | wxTE_MULTILINE, wxDefaultValidator, wxT("OutputEditBox"));
	OutputEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Bitstream Vera Sans Mono")));

	ShowPacketsToggleButton = new wxToggleButton(WxProxyPage, ID_SHOWPACKETSTOGGLEBUTTON, wxT("Show Packets"), wxPoint(436,68), wxSize(76,24), 0, wxDefaultValidator, wxT("ShowPacketsToggleButton"));
	ShowPacketsToggleButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	ClearLogButton = new wxButton(WxProxyPage, ID_CLEARLOGBUTTON, wxT("Clear Log"), wxPoint(436,120), wxSize(76,24), 0, wxDefaultValidator, wxT("ClearLogButton"));
	ClearLogButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	ClearPacketsButton = new wxButton(WxProxyPage, ID_CLEARPACKETSBUTTON, wxT("Clear Packets"), wxPoint(436,95), wxSize(76,24), 0, wxDefaultValidator, wxT("ClearPacketsButton"));
	ClearPacketsButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	PacketEditBox = new wxTextCtrl(WxProxyPage, ID_PACKETEDITBOX, wxT(""), wxPoint(2,150), wxSize(510,150), wxVSCROLL | wxTE_MULTILINE, wxDefaultValidator, wxT("PacketEditBox"));
	PacketEditBox->Show(false);
	PacketEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Bitstream Vera Sans Mono")));

	GameNoteBookPage = new wxPanel(MainNotebook, ID_GAMENOTEBOOKPAGE, wxPoint(4,24), wxSize(514,307));
	GameNoteBookPage->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
	MainNotebook->AddPage(GameNoteBookPage, wxT("Game"));

	MsgLogNoteBookPage = new wxPanel(MainNotebook, ID_MSGLOGNOTEBOOKPAGE, wxPoint(4,24), wxSize(514,307));
	MsgLogNoteBookPage->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
	MainNotebook->AddPage(MsgLogNoteBookPage, wxT("MsgLog"));

	ChannelsStaticBox = new wxStaticBox(MsgLogNoteBookPage, ID_CHANNELSSTATICBOX, wxT("Channels"), wxPoint(6,6), wxSize(100,200));
	ChannelsStaticBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	wxArrayString arrayStringFor_ChannelListBox;
	ChannelListBox = new wxListBox(MsgLogNoteBookPage, ID_CHANNELLISTBOX, wxPoint(12,23), wxSize(88,178), arrayStringFor_ChannelListBox, wxLB_SINGLE | wxVSCROLL);
	ChannelListBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	LogStaticBox = new wxStaticBox(MsgLogNoteBookPage, ID_LOGSTATICBOX, wxT("Log"), wxPoint(112,6), wxSize(400,200));
	LogStaticBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	wxArrayString arrayStringFor_MessageListBox;
	MessageListBox = new wxListBox(MsgLogNoteBookPage, ID_MESSAGELISTBOX, wxPoint(118,23), wxSize(388,178), arrayStringFor_MessageListBox, wxLB_SINGLE | wxVSCROLL);
	MessageListBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MessageInfoStaticBox = new wxStaticBox(MsgLogNoteBookPage, ID_MESSAGEINFOSTATICBOX, wxT("Message Info"), wxPoint(112,210), wxSize(400,90));
	MessageInfoStaticBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MISenderEditBox = new wxTextCtrl(MsgLogNoteBookPage, ID_MISENDEREDITBOX, wxT("Name"), wxPoint(166,227), wxSize(80,19), wxTE_READONLY, wxDefaultValidator, wxT("MISenderEditBox"));
	MISenderEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	SenderStaticText = new wxStaticText(MsgLogNoteBookPage, ID_SENDERSTATICTEXT, wxT("Sender:"), wxPoint(125,230), wxDefaultSize, 0, wxT("SenderStaticText"));
	SenderStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIChannelStaticText = new wxStaticText(MsgLogNoteBookPage, ID_MICHANNELSTATICTEXT, wxT("Channel:"), wxPoint(252,230), wxDefaultSize, 0, wxT("MIChannelStaticText"));
	MIChannelStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIChannelEditBox = new wxTextCtrl(MsgLogNoteBookPage, ID_MICHANNELEDITBOX, wxT("Channel"), wxPoint(298,227), wxSize(80,19), wxTE_READONLY, wxDefaultValidator, wxT("MIChannelEditBox"));
	MIChannelEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MITimeStaticText = new wxStaticText(MsgLogNoteBookPage, ID_MITIMESTATICTEXT, wxT("Time:"), wxPoint(384,230), wxDefaultSize, 0, wxT("MITimeStaticText"));
	MITimeStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MITimeEditBox = new wxTextCtrl(MsgLogNoteBookPage, ID_MITIMEEDITBOX, wxT("Time"), wxPoint(413,227), wxSize(80,19), wxTE_READONLY, wxDefaultValidator, wxT("MITimeEditBox"));
	MITimeEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIMessageEditBox = new wxTextCtrl(MsgLogNoteBookPage, ID_MIMESSAGEEDITBOX, wxT("Message"), wxPoint(166,252), wxSize(340,40), wxVSCROLL | wxTE_READONLY | wxTE_MULTILINE, wxDefaultValidator, wxT("MIMessageEditBox"));
	MIMessageEditBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIMessageStaticText = new wxStaticText(MsgLogNoteBookPage, ID_MIMESSAGESTATICTEXT, wxT("Message:"), wxPoint(117,253), wxDefaultSize, 0, wxT("MIMessageStaticText"));
	MIMessageStaticText->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIClearChannelButton = new wxButton(MsgLogNoteBookPage, ID_MICLEARCHANNELBUTTON, wxT("Clear Channel"), wxPoint(6,210), wxSize(100,26), 0, wxDefaultValidator, wxT("MIClearChannelButton"));
	MIClearChannelButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	MIClearAllLogsButton = new wxButton(MsgLogNoteBookPage, ID_MICLEARALLLOGSBUTTON, wxT("Clear All Logs"), wxPoint(6,238), wxSize(100,26), 0, wxDefaultValidator, wxT("MIClearAllLogsButton"));
	MIClearAllLogsButton->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	WxToolBar1 = new wxToolBar(this, ID_WXTOOLBAR1, wxPoint(0,0), wxSize(522,21), wxRAISED_BORDER);
	WxToolBar1->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));

	wxArrayString arrayStringFor_ToolBarClientSelectComboBox;
	ToolBarClientSelectComboBox = new wxComboBox(WxToolBar1, ID_TOOLBARCLIENTSELECTCOMBOBOX, wxT(""), wxPoint(0,0), wxSize(120,21), arrayStringFor_ToolBarClientSelectComboBox, wxTE_READONLY, wxDefaultValidator, wxT("ToolBarClientSelectComboBox"));
	ToolBarClientSelectComboBox->SetFont(wxFont(8, wxSWISS, wxNORMAL,wxNORMAL, false, wxT("Tahoma")));
	WxToolBar1->AddControl(ToolBarClientSelectComboBox);

	WxToolBar1->Realize();
	SetToolBar(WxToolBar1);
	SetTitle(wxT("DeadProxy"));
	SetIcon(wxNullIcon);
	SetSize(8,8,530,390);
	Center();
	
	////GUI Items Creation End
	pMiniClientCanvas = new MiniClientCanvas(GameNoteBookPage, wxID_ANY, 0, wxPoint(0,0), wxSize(360, 264));
}

//Overwritten winproc function
WXLRESULT DeadProxyFrm::MSWWindowProc(WXUINT nMsg, WXWPARAM wParam, WXLPARAM lParam)
{
    if(nMsg == WM_WSAASYNC)
    {
        app->Network->Message(wParam, lParam);
    }
    return wxFrame::MSWWindowProc(nMsg, wParam, lParam);
}

void DeadProxyFrm::OnClose(wxCloseEvent& event)
{
	Destroy();
}


void DeadProxyFrm::LogMessage(wxLogMessageEvent& event)
{
    OutputEditBox->AppendText(wxT("\n"));
    event.GetMessage();
    OutputEditBox->AppendText(*event.GetMessage());
}

void DeadProxyFrm::UpdateClientBox(wxGUIEvent & event)
{
    int op = event.GetParam2();
    switch(op)
    {
        case 0:
            ClientSelectListBox->Insert(*event.GetStr1(), ClientSelectListBox->GetCount());
            ToolBarClientSelectComboBox->Insert(*event.GetStr1(), ToolBarClientSelectComboBox->GetCount());
            if(ClientSelectListBox->GetCount() == 1)
            {
                ClientSelectListBox->SetSelection(0);
                ToolBarClientSelectComboBox->SetSelection(0);
                OnClientSelected(0);
            }
            break;
        case 1:
            ClientSelectListBox->Delete(event.GetParam1());
            ClientSelectListBox->Insert(*event.GetStr1(), event.GetParam1());
            ToolBarClientSelectComboBox->Delete(event.GetParam1());
            ToolBarClientSelectComboBox->Insert(*event.GetStr1(), event.GetParam1());
            break;
        case 2:
            ClientSelectListBox->Delete(event.GetParam1());
            ToolBarClientSelectComboBox->Delete(event.GetParam1());
            break;
    }
}

void DeadProxyFrm::UpdatePacketBox(wxGUIEvent & event)
{
    int op = event.GetParam2();
    switch(op)
    {
        case 0:
            SelectPacketListBox->Insert(*event.GetStr1(), SelectPacketListBox->GetCount());
            break;
        case 1:
            SelectPacketListBox->Delete(event.GetParam1());
            SelectPacketListBox->Insert(*event.GetStr1(), event.GetParam1());
            break;
        case 2:
            SelectPacketListBox->Delete(event.GetParam1());
            break;
    }
}

/*
 * TestButtonClick
 */
void DeadProxyFrm::TestButtonClick(wxCommandEvent& event)
{
    app->TestFunc();    
}

/*
 * LaunchClientButtonClick
 */
void DeadProxyFrm::LaunchClientButtonClick(wxCommandEvent& event)
{
	app->LaunchClient();
}

/*
 * WxCheckBox1Click
 */
void DeadProxyFrm::WxCheckBox1Click(wxCommandEvent& event)
{
}

/*
 * ShowPacketsCheckboxClick
 */
void DeadProxyFrm::ShowPacketsCheckboxClick(wxCommandEvent& event)
{

}

/*
 * ShowPacketsToggleButtonClick
 */
void DeadProxyFrm::ShowPacketsToggleButtonClick(wxCommandEvent& event)
{
    if(ShowPacketsToggleButton->GetValue())
    {
        ShowPacketsToggleButton->SetLabel(wxT("Hide Packets"));
    	OutputEditBox->Show(false);
    	PacketEditBox->Show(true);
    } else {
        ShowPacketsToggleButton->SetLabel(wxT("Show Packets"));
    	PacketEditBox->Show(false);
    	OutputEditBox->Show(true);
    }
}

/*
 * ClientSelectListBoxSelected
 */
void DeadProxyFrm::ClientSelectListBoxSelected(wxCommandEvent& event)
{
	ClientIndex = ClientSelectListBox->GetSelection();
	if(ClientIndex != wxNOT_FOUND)
    {
        ToolBarClientSelectComboBox->SetSelection(ClientSelectListBox->GetSelection());
        OnClientSelected(ClientIndex);
    }
}

/*
 * ToolBarClientSelectComboBoxSelected
 */
void DeadProxyFrm::ToolBarClientSelectComboBoxSelected(wxCommandEvent& event )
{
	ClientIndex = ToolBarClientSelectComboBox->GetSelection();
	if(ClientIndex != wxNOT_FOUND)
    {
        ClientSelectListBox->SetSelection(ToolBarClientSelectComboBox->GetSelection());
        OnClientSelected(ClientIndex);
    }
}

void DeadProxyFrm::OnClientSelected(int index)
{
    ClientEvent * Deselect = new ClientEvent(CE_SET_SELECTED);
    Deselect->SetParam1(0);
    app->CManager->BroadcastEvent(Deselect);
    ClientEvent * Select = new ClientEvent(CE_SET_SELECTED);
    Select->SetParam1(1);
    app->CManager->PostEventToClient(index, Select);
    //Load Packet Log
    //LogPacketsRadioBox->SetSelection(app->CManager->GetLogPacketMode(ClientIndex));
    //wxArrayString * values = app->CManager->GetListBoxArray(ClientIndex);
    //SelectPacketListBox->Set(*values);
    //delete values;
}

void DeadProxyFrm::InitClientSelect(wxGUIEvent & event)
{
    Client::InitSelectInfo * ISI = (Client::InitSelectInfo*)event.GetParam1();
    LogPacketsRadioBox->SetSelection(ISI->LogPacketMode);
    SelectPacketListBox->Set(*(ISI->PacketSelectListBoxArray));
    delete ISI->PacketSelectListBoxArray;
    delete ISI;
}

/*
 * LogPacketsRadioBoxClick
 */
void DeadProxyFrm::LogPacketsRadioBoxClick(wxCommandEvent& event)
{
    ClientIndex = ClientSelectListBox->GetSelection();
    if(ClientIndex != wxNOT_FOUND)
    {
        ClientEvent * evt = new ClientEvent(CE_SETLOGMODE);
        evt->SetParam1(LogPacketsRadioBox->GetSelection());
	    app->CManager->PostEventToClient(ClientIndex, evt);
    }
}

/*
 * SelectPacketListBoxSelected
 */
void DeadProxyFrm::SelectPacketListBoxSelected(wxCommandEvent& event)
{
    ClientIndex = ClientSelectListBox->GetSelection();
	if(ShowPacketsToggleButton->GetValue() && ClientIndex != wxNOT_FOUND)
	{
        ClientEvent * evt = new ClientEvent(CE_GET_PACKET_STRING);
        evt->SetParam1(SelectPacketListBox->GetSelection());
        app->CManager->PostEventToClient(ClientIndex, evt);
//        wxString * value = app->CManager->GetPacketString(ClientIndex, SelectPacketListBox->GetSelection());
//        PacketEditBox->SetValue(*value);
//        delete value;
    }
}

//Set Packet Box
void DeadProxyFrm::SetPacketString(wxGUIEvent & event)
{
    PacketEditBox->SetValue(*event.GetStr1());
}

/*
 * ClearPacketsButtonClick
 */
void DeadProxyFrm::ClearPacketsButtonClick(wxCommandEvent& event)
{
	ClientIndex = ClientSelectListBox->GetSelection();
	if(ShowPacketsToggleButton->GetValue() && ClientIndex != wxNOT_FOUND)
	{
        //app->CManager->ClearPacketLog(ClientIndex);
        ClientEvent * ClearPacketLogEvent = new ClientEvent(CE_CLEAR_PACKET_LOG);
        app->CManager->PostEventToClient(ClientSelectListBox->GetSelection(), ClearPacketLogEvent);
    }
    SelectPacketListBox->Clear();
}

void DeadProxyFrm::SetMessageInfo(wxGUIEvent & event)
{
    wxArrayString * MessageInfo = (wxArrayString *)(event.GetParam1());
    MISenderEditBox->SetValue(MessageInfo->Item(0));
    MIChannelEditBox->SetValue(MessageInfo->Item(1));
    MITimeEditBox->SetValue(MessageInfo->Item(2));
    MIMessageEditBox->SetValue(MessageInfo->Item(3));
    delete MessageInfo;
}

void DeadProxyFrm::SetMessageArray(wxGUIEvent & event)
{
    wxArrayString * MessageArray = (wxArrayString *)(event.GetParam1());
    MessageListBox->Set(*MessageArray);
    delete MessageArray;
}
    

/*
 * ClearLogButtonClick
 */
void DeadProxyFrm::ClearLogButtonClick(wxCommandEvent& event)
{
	OutputEditBox->Clear();
}

void DeadProxyFrm::UpdateChannelBox(wxGUIEvent & event)
{
    int op = event.GetParam2();
    switch(op)
    {
        case 0:
            ChannelListBox->Insert(*event.GetStr1(),ChannelListBox->GetCount());
            break;
        case 2:
            ChannelListBox->Delete(event.GetParam1());
            break;
        case 3:
            ChannelListBox->Clear();
            break;
    }
}

void DeadProxyFrm::UpdateMessageBox(wxGUIEvent & event)
{
    int op = event.GetParam2();
    switch(op)
    {
        case 0:
            MessageListBox->Insert(*event.GetStr1(), MessageListBox->GetCount());
            break;
        case 3:
            MessageListBox->Clear();
            break;
        case 4:
            MessageListBox->Set(*(wxArrayString*)event.GetParam1());
            delete (wxArrayString*)event.GetParam1();
            break;
    }
}


/*
 * WxComboBox1Selected
 */
void DeadProxyFrm::WxComboBox1Selected(wxCommandEvent& event )
{
	// insert your code here
}

/*
 * ChannelListBoxSelected
 */
void DeadProxyFrm::ChannelListBoxSelected(wxCommandEvent& event)
{
    ClientEvent * evt = new ClientEvent(CE_SET_SELECTED_CHANNEL);
    evt->SetParam1(ChannelListBox->GetSelection());
    app->CManager->PostEventToClient(ClientSelectListBox->GetSelection(), evt);
}

/*
 * MessageListBoxSelected
 */
void DeadProxyFrm::MessageListBoxSelected(wxCommandEvent& event)
{
	ClientEvent * evt = new ClientEvent(CE_GET_MESSAGE_INFO);
    evt->SetParam1(ChannelListBox->GetSelection());
    evt->SetParam2(MessageListBox->GetSelection());
    app->CManager->PostEventToClient(ClientSelectListBox->GetSelection(), evt);
}

/*
 * MIClearChannelButtonClick
 */
void DeadProxyFrm::MIClearChannelButtonClick(wxCommandEvent& event)
{
	ClientEvent * evt = new ClientEvent(CE_CLEAR_MESSAGE_LOG);
	evt->SetParam1(ChannelListBox->GetSelection());
	evt->SetParam2(0);
	app->CManager->PostEventToClient(ClientSelectListBox->GetSelection(), evt);
}

/*
 * MIClearAllLogsButtonClick
 */
void DeadProxyFrm::MIClearAllLogsButtonClick(wxCommandEvent& event)
{
    
	ClientEvent * evt = new ClientEvent(CE_CLEAR_MESSAGE_LOG);
	evt->SetParam2(1);
	app->CManager->PostEventToClient(ClientSelectListBox->GetSelection(), evt);
}
